/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FeedBackDialog.java
 *
 * Created on 16.3.2011, 9:19:20
 */
package cz.muni.fi.rum.gui.component;

import cz.muni.fi.rum.RumConfigurator;
import javax.swing.JFrame;
import org.jdesktop.application.Action;

/**
 *
 * @author pmikulasek
 */
public class FeedBackDialog extends javax.swing.JDialog {

    private static FeedBackDialog instance;

    /** Creates new form FeedBackDialog */
    private FeedBackDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    private static FeedBackDialog getInstance() {
        if(instance == null){
            JFrame mainFrame = RumConfigurator.getApplication().getMainFrame();
            instance = new FeedBackDialog(mainFrame, true);
            instance.setLocationRelativeTo(mainFrame);
        }
        return instance;
    }

    private static void showDialog(){
        RumConfigurator.getApplication().show(getInstance());
    }

    public static void showMessage(String message) {
        //TODO nastavit cernou barvu pisma
        getInstance().feedBackLabel.setText(message);
        showDialog();
    }

    public static void showErrorMessage(String errorMessage) {
        //TODO nastavit cervenou barvu pisma
        getInstance().feedBackLabel.setText(errorMessage);
        showDialog();
    }

    @Action public void closeDialog() {
        dispose();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        feedBackBorderPane = new javax.swing.JPanel();
        feedBackLabel = new javax.swing.JLabel();
        closeButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cz.muni.fi.rum.RumConfigurator.class).getContext().getResourceMap(FeedBackDialog.class);
        feedBackBorderPane.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("feedBackBorderPane.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), resourceMap.getColor("feedBackBorderPane.border.titleColor"))); // NOI18N
        feedBackBorderPane.setName("feedBackBorderPane"); // NOI18N

        feedBackLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        feedBackLabel.setAutoscrolls(true);
        feedBackLabel.setName("feedBackLabel"); // NOI18N

        javax.swing.GroupLayout feedBackBorderPaneLayout = new javax.swing.GroupLayout(feedBackBorderPane);
        feedBackBorderPane.setLayout(feedBackBorderPaneLayout);
        feedBackBorderPaneLayout.setHorizontalGroup(
            feedBackBorderPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(feedBackLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
        );
        feedBackBorderPaneLayout.setVerticalGroup(
            feedBackBorderPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(feedBackLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
        );

        closeButton.setText(resourceMap.getString("closeButton.text")); // NOI18N
        closeButton.setName("closeButton"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(158, Short.MAX_VALUE)
                        .addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(feedBackBorderPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(feedBackBorderPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(closeButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton closeButton;
    private javax.swing.JPanel feedBackBorderPane;
    private javax.swing.JLabel feedBackLabel;
    // End of variables declaration//GEN-END:variables
}
